/**
 * 
 */
package controllers;

import client.gui.panels.PanelIF;
import client.gui.panels.TimeFrameApprovalByInspectorPanel;
import entities.Message;
import entities.MsgType;
import entities.ObjectType;

/**
 * @author Vodi
 *
 */
public class TimeFrameApprovalByInspectorController implements ControllerIF {
	
	/**
	 * the time frame approval panel
	 */
	private TimeFrameApprovalByInspectorPanel timeFrameApprovalByInspectorPanel;

	/**
	 * reference of the hosting panel's controller
	 */
	private ViewTicketController hostController; 
	
	/**
	 * String holding the current ticket's state
	 */
	private String ticketStage;
	
	/**
	 * the duration inserted by the inspector
	 */
	private Integer timeDuration; 
	
	public TimeFrameApprovalByInspectorController(ControllerIF hostController, String ticketStage) {
		this.hostController = (ViewTicketController) hostController;
		this.ticketStage = ticketStage;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#getPanel()
	 */
	@Override
	public PanelIF getPanel() {
		return timeFrameApprovalByInspectorPanel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#setPanel(client.gui.panels.PanelIF)
	 */
	@Override
	public void setPanel(PanelIF panel) {
		this.timeFrameApprovalByInspectorPanel = (TimeFrameApprovalByInspectorPanel) panel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#action()
	 */
	@Override
	public void action() {
		MsgType msgType = null;
		timeDuration = timeFrameApprovalByInspectorPanel.getInspectorDecision();
		
		if(ticketStage.equals("EVALUATION_DURATION_APPROVAL")) {
			msgType = MsgType.APPROVE_EVALUATION_DURATION_RESPONSE;
		}
		else if(ticketStage.equals("EXECUTION_DURATION_APPROVAL")) {
			msgType = MsgType.APPROVE_EXECUTION_DURATION_REQUEST;
		}
		Message message = new Message(msgType, ObjectType.STRING, timeDuration.toString());
		hostController.sendMessage(message);
	}

	/**
	 * @return the time duration allocated by the inspector
	 */
	public Integer getTimeDuration() {
		return timeDuration;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#decipherMessage(entities.Message)
	 */
	@Override
	public void decipherMessage(Message message) {}

}
